@include('admin.header')
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">

    <form method="post" class="form-horizontal js-category-add">
        <input type="hidden" name="source_type" value="{{Request::get('source_type')}}">
        <input type="hidden" name="rate" value="{{$data['rate']}}">
        <div class="row-fluid">
            <table class="table table-bordered">
                <tr>
                    <th colspan="2">当前每日最高可提现<span>{{$data['extraCash']}}</span>元</th>
                </tr>
                <tr>
                    <th width="200">到账银行</th>
                    <td>
                        <input type="text" style="width:400px;" name=""  value="{{$data['bankInfo']->bank_name}}(尾号{{substr($data['bankInfo']->bank_account_no,-4)}})" placeholder="" readonly/>
                    </td>
                </tr>
                <tr>
                    <th>可提现最大金额</th>
                    <td>
                        <span style="margin-right: 50px;">{{$data['enableCash']}}元</span>
                        <button class="btn btn-info" type="button" data-max="{{$data['enableCash']}}" id="all-withdraw">全部提现</button>
                    </td>
                </tr>
                <tr>
                    <th>提现金额</th>
                    <td>
                        <input type="number" style="width:200px;" name="money"  value="" placeholder="请输入提现金额" max="{{$data['enableCash']}}" min="0" step="0.01"/>
                        <span>手续费:<span id="poundage"></span>元</span>
                    </td>
                </tr>
                <tr>
                    <th>短信验证码</th>
                    <td>
                        <input type="text" style="width:200px;" name="phone_verify_code"  value="" placeholder="请输入短信验证码"/>
                        <button class="btn btn-primary" type="button" id="sendSms">发送验证码</button>
                    </td>
                </tr>
                <tr>
                   <td colspan="2">
                       <button class="btn btn-success js-ajax-submit" type="button" id="withdraw">确定提现</button>
                       <button class="btn" type="button" onclick="window.history.go(-1);">返回</button>
                   </td>
                </tr>
                <tr>
                    <td colspan="2" style="padding-left: 30px;">
                        <span>提现须知</span>
                        <ul>
                            <li>支持金额：最低提现金额为100元。</li>
                            <li>安全提示：根据国家反洗钱政策及保障客户资产安全，会对系统检测出的异常账户进行安全认证。</li>
                            <li>到账时间：正常24小时内到账，具体到账时间因收款银行略有不同，节假日到账时间略有延迟。</li>
                            <li>费率标准：提现时会收取一定的手续费，最低收取1元提现费用。</li>
                        </ul>
                    </td>
                </tr>
            </table>
        </div>
        <input type="hidden" name="_token"  value="{{csrf_token()}}"/>
    </form>
</div>
<script type="text/javascript" src="/static/js/common.js"></script>
<script type="text/javascript" src="/static/js/validate/validate.js"></script>
<script type="text/javascript" src="/static/js/layer/layer.js"></script>
<script type="text/javascript">

    function showMsg(msg){
        layer.alert(msg, {
            title: '提示',
            icon: 2,
        });
    }

    //点击全部提现
    $('#all-withdraw').on('click',function () {
        var maxValue=this.getAttribute('data-max');
        if(isNaN(maxValue))
        {
            showMsg('数字格式有误');
            return false;
        }
        $('[name=money]').val(maxValue).trigger('input');//触发input变化
    });

    //监听数字变化
    $('[name=money]').on('input',function () {
        var rate=$('[name=rate]').val();
        $('#poundage').text(parseInt(rate*this.value*10000)/10000);
    });

    //发送验证码
    var time=0;
    var interval;
    $('#sendSms').on('click',function () {
        var _this=this;
        if(time>0){
            return false;
        }
        _this.disabled=true;//禁用
        $.post('{{url('settle/send_sms')}}',{},function(data){
            if(data.status==1){
                time=60;
                interval=setInterval(function(){
                    time--;
                    if(time<=0){
                        clearInterval(interval);
                        _this.disabled=false;
                        _this.innerText='发送验证码';
                    }else{
                        _this.disabled=true;
                        _this.innerText=time+'秒';
                    }
                },1000);
            }else{
                showMsg(data.msg);return false;
            }
        },'json');
    });

    //点击提现
    $('#withdraw').on('click',function () {
        var _this=this;
        var tmp={};
        tmp.apply_amount=$('[name=money]').val();
        tmp.phone_verify_code=$('[name=phone_verify_code]').val();
        tmp.source_type=$('[name=source_type]').val();
        if(isNaN(tmp.apply_amount)){
            showMsg('请输入提现金额');
            return false;
        }
        if(tmp.phone_verify_code.length<3){
            showMsg('请输入验证码');
            return false;
        }
        _this.disabled=true;
        $.post('{{url('settle/apply_withdraw')}}',tmp,function(data){
            if(data.status==1){
                showMsg(data.msg);
            }else{
                showMsg(data.msg);
                _this.disabled=false;
            }
            return false;
        },'json');
    });
</script>
</body>
</html>